const categoryModel= require('../models/Category');
const logUtil = require('../../untils/logUtil');
const success = require('../success');
const error = require('../error');
const Sequelize = require('sequelize');
const Op = Sequelize.Op;

class Category {
    constructor() {
        // super()
    }

    //获取导航
    async getNav(req, res, next) {
        try {
            let datas = await categoryModel.findAll({
                where: {
                    status:1,
                    parent_id:0
                },
                attributes: ['id', 'name'],
                order: [['orderby', 'desc'],['id','asc']],
            });
            res.json(
                success(datas)
            );
        } catch (err) {
            logUtil.error(err, req);
            res.json(
                error(err.message)
            );
        }
    }

    //获取分类
    async getList(req, res, next) {
        try {
            let datas = await categoryModel.findAll({
                where: {
                    status:1,
                    is_xilie:0
                },
                attributes: ['id', 'name'],
                order: [['orderby', 'asc'],['id','asc']],
            });
            res.json(
                success(datas)
            );
        } catch (err) {
            logUtil.error(err, req);
            res.json(
                error(err.message)
            );
        }
    }
    //获取系列
    async getxilie(req, res, next) {
        try {
            let datas = await categoryModel.findAll({
                where: {
                    status:1,
                    is_xilie:1
                },
                attributes: ['id', 'name'],
                order: [['orderby', 'asc'],['id','asc']],
            });
            res.json(
                success(datas)
            );
        } catch (err) {
            logUtil.error(err, req);
            res.json(
                error(err.message)
            );
        }
    }
}

module.exports = new Category();
